package com.cys.dm.rest.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cys.dm.dao.item.DmItemCommentDao;
import com.cys.dm.entity.item.DmItemComment;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
public class DmItemCommentService {
    @Resource
    private DmItemCommentDao dmItemCommentDao;

    @PostMapping(path = "/findAllByItemId")
    public List<DmItemComment> findAllByItemId(@RequestParam Long itemId){
        QueryWrapper<DmItemComment> dmItemCommentQueryWrapper = new QueryWrapper<>();
        dmItemCommentQueryWrapper.eq("itemId",itemId);
        return dmItemCommentDao.selectList(dmItemCommentQueryWrapper);
    }

    @PostMapping(path = "/commitItemComment")
    public int commitItemComment(@RequestParam Map<String,Object> params){
        DmItemComment dmItemComment = new DmItemComment();
        dmItemComment.setItemId((Long) params.get("itemId"));
        dmItemComment.setUserId((Long) params.get("userId"));
        dmItemComment.setScore((Long) params.get("score"));
        dmItemComment.setContent(params.get("content").toString());
        return dmItemCommentDao.insert(dmItemComment);
    }
}
